#include "textbuffer.hpp"

#include <assert.h>

TextBuffer::TextBuffer()
  :lines_()
{

}

TextBuffer::~TextBuffer()
{

}

void TextBuffer::LoadFromMemory(unsigned char * dat, 
				int len )
{
  lines_.erase(lines_.begin(),lines_.end());
  if(len>0)
    {
      std::string curStr = std::string();
      for(unsigned int i=0; i!=len; i++ )
	{
	  if(dat[i]=='\0')
	    {
			break;
	      
	    }
	  else if(dat[i]=='\n')
	    {
	      lines_.push_back(curStr);
		  curStr = std::string("");
	    }
	  else
	    {
	      curStr+=dat[i];
	    }
	}
	  lines_.push_back(curStr);
	  return;
    }
}

std::string* TextBuffer::GetLine(unsigned int idl)
{
  if(idl < lines_.size())
    {
      return &(lines_.at(idl));
    }
  return NULL;
}

void TextBuffer::serializeUp()
{

}

void TextBuffer::serializeDown()
{

}

